home *** CD-ROM | disk | FTP | other *** search
- // TESTPROG.C
- //
- //
- // This program demonstrates the use of hardware locks (using
- // FAKELOCK to simulate the hardware lock). TESTPROG has four
- // functions, two of which (func2 and func3) are designed to be
- // used frequently when running TESTPROG. TESTPROG calls FAKELOCK
- // when the TESTPROG starts and every time func2 and func3 are called.
- //
- // The program TESTLOCK was used to determine what values FAKELOCK
- // would return for the given parameters.
- //
- // The function CALL_LOCK calls FAKELOCK.
- // CALL_LOCK gives TESTPROG a uniform response to failing
- // the hardware lock test. Instead of just exiting the program,
- // CALL_LOCK gives the user the chance to restore the lock
- // and continue. This was done so that any data in memory
- // might be saved before the program returned to DOS.
-
- #include <stdlib.h>
- #include <stdio.h>
- #include "fakelock.h"
-
- // function prototypes
- void CALL_LOCK( char *incode );
- void func1( char* msg );
- void func2( char* msg );
- void func3( char* msg );
- void func4( char* msg );
-
- void main( void )
- {
- CALL_LOCK( "abcdefgh" );
-
- func1( "\nfirst time in function 1" );
- func2( "\nfirst time in function 2" );
- func3( "\nfirst time in function 3" );
- func2( "\nsecond time in function 2" );
- func2( "\nthird time in function 2" );
- func3( "\nsecond time in function 3" );
- func2( "\nfourth time in function 2" );
- func4( "\nfirst time in function 4" );
-
- printf("\nProgram finished normally");
- };
-
- void func1( char* msg )
- {
- printf("%s", msg );
- };
-
- void func2( char* msg )
- {
- CALL_LOCK( "abcdefgh" );
- printf("%s", msg );
- };
-
- void func3( char* msg )
- {
- CALL_LOCK( "abcdefgh" );
- printf("%s", msg );
- };
-
- void func4( char* msg )
- {
- char test[96];
-
- printf("\nEnter any lock parameter you want (only 'abcdefgh'"
- " will find lock): ");
- gets( test );
- CALL_LOCK( test );
- printf("%s", msg );
- };
-
- void CALL_LOCK( char *incode )
- {
- int key;
- char lock[96];
- int results = 0;
-
- printf("\nWhich lock is to be called (1 or 2): ");
- gets( lock );
- key = atoi( lock );
-
- while (results != 19334)
- {
- if ( (results = FAKELOCK( incode, key )) != 19334 )
- {
- printf("FAKE LOCK returned %d, that did not match the known key",
- results );
- printf("\nEnter another lock to try (0 to exit to DOS, or 1 or 2): ");
- gets( lock );
- key = atoi( lock );
-
- if ( key == 0 )
- {
- printf("Program ended because it could not find hardware lock");
- exit( 0 );
- }
- }
- }
- return;
- }
-